package brickBreaker;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Circle;

import states.SlickGame;
import globals.DataTracker;
import globals.FreeVector;
import interfaces.Trackable;

public class Ball extends Trackable{
	// From Trackable
	// public int x,y,r;
	public FreeVector direction;
	Color ballColor=Color.red;
	
	public Ball(int xpos, int ypos, int rval) {
		super(xpos, ypos, rval);
		direction=new FreeVector(5,(float)(0.3*Math.PI));
	}
	
	public void update(){
		// Boundry Checks.
		if(x-r<0){direction.add(new FreeVector(5,0));}
		else if(x+r>SlickGame.width){direction.add(new FreeVector(5,(float)(Math.PI)));}
		
		if(y-r<0){direction.add(new FreeVector(5,(float)(Math.PI/2)));}
		else if(y+r>SlickGame.height+50){direction.add(new FreeVector(5,(float)((3*Math.PI)/2)));}
		
		
		// Position Change.
		x+=direction.getX();
		y+=direction.getY();
	}
	
	public void update(DataTracker dataOut){
		// Boundry Checks.
		if(x-r<0){direction.add(new FreeVector(5,0));}
		else if(x+r>SlickGame.width){direction.add(new FreeVector(5,(float)(Math.PI)));}
		
		if(y-r<0){direction.add(new FreeVector(5,(float)(Math.PI/2)));}
		else if(y+r>SlickGame.height+50){direction.add(new FreeVector(5,(float)((3*Math.PI)/2)));}
		
		
		// Position Change.
		x+=direction.getX();
		y+=direction.getY();
		
		dataOut.updatefloat(x, y, direction.getMagnatude());
	}
	
	public void draw(Graphics g){
		g.setColor(ballColor);
		g.fill(new Circle(x,y,r));
		g.setLineWidth(2);
		g.setColor(ballColor.darker());
		g.draw(new Circle(x,y,r));
		g.setLineWidth(1);
	}

}
